import { useTable, LIST_TYPE } from '@crud/index';
import { getColonelList } from '@/api/crm-agency/dyj/colonel';
import { toolOptions2Map } from '@/utils';
// 查询
export const levelOptions = [
  { label: 'A级', value: 1 },
  { label: 'S级', value: 2 }
];
export const levelMap = toolOptions2Map(levelOptions);
// 表格
export const useTableList = (options: any = {}) => {
  const columns: any = [
    { label: '代理名称', prop: 'name', minWidth: 200, fixed: 'left' },
    { label: '代理账号', prop: 'mobile', minWidth: 160 },
    { label: '代理类型', prop: 'level', minWidth: 120, render: (s:any) => levelMap[s.row.dyj_level] || '-' },
    { label: '加入时间', prop: 'add_time', minWidth: 160, type: 'date' },
    { label: '新/老用户数', prop: 'user', minWidth: 120, render: 'user' },
    { label: '订单总数', prop: 'order_count', minWidth: 120, render: 'order_count' },
    { label: '订单总额', prop: 'total_fee', minWidth: 120 },
    { label: '佣金余额', prop: 'commission_fee', minWidth: 120 },
    { label: '佣金总收益', prop: 'commission_total', minWidth: 120 },
    { label: '保证金', prop: 'dyj_safty', minWidth: 120 },
    { label: '操作', width: 200, align: 'center', render: 'actions', fixed: 'right' }
  ];

  return useTable({
    ...options,
    type: LIST_TYPE.AGENCY,
    params: {
      extend_type: 2,
      keyword: '',
      from_dt: undefined,
      to_dt: undefined
    },
    columns: columns,
    getParams: ({ _timeArr = [], ...params }) => {
      // 处理时间参数
      if (_timeArr?.length) {
        const [begin, end] = _timeArr;
        params.from_dt = begin;
        params.to_dt = end;
      }
      return params;
    },
    getList: getColonelList
  });
};
